import axios from 'axios'

axios.defaults.timeout = 10000
// 存放项目的后台api接口位置
const Path = "124.221.207.2:8521"
const httpPath = `http://${Path}`
export const TIME_SPLIT = 86400
// 返回格式化的时间字符串 YY-MM-DD hh:mm:ss
export function getTime(){
    const date = new Date()
    let result = ""
    result += date.getFullYear().toString() + "-"
    result += (date.getMonth() < 9 ? '0' : '') + (date.getMonth() + 1).toString() + '-'
    result += (date.getDate() < 10 ? '0' : '') + date.getDate().toString() + ' '
    result += (date.getHours() < 10 ? '0' : '') + date.getHours().toString() + ':'
    result += (date.getMinutes() < 10 ? '0' : '') + date.getMinutes().toString() + ':'
    result += (date.getSeconds() < 10 ? '0' : '') + date.getSeconds().toString()
    return result
}
// 返回格式化时间字符串的时间戳
export function numTime(time){
    // 2022-12-15 08:19:18
    const date = new Date()
    date.setFullYear(Number(time.slice(0, 4)))
    date.setMonth(Number(time.slice(5, 7)) - 1)
    date.setDate(Number(time.slice(8, 10)))
    date.setHours(Number(time.slice(11, 13)))
    date.setMinutes(Number(time.slice(14, 16)))
    date.setSeconds(Number(time.slice(17, 19)))
    return date.valueOf()

}


export function someUser(id ){
    let result = ""
    axios.post(`${httpPath}/api/someUser`, {"id": id}).then(res=>{
        result = res.data
    })
    return result
}


export function post(url, data){
    return new Promise((resolve, reject) => {
        axios.post(`${httpPath}` + url, data
        ).then(res => {
            resolve(res)
        }).catch(err => {
            reject(err.data)
        })
    })
}

export function get(url, params){
    return new Promise((resolve, reject) => {
        axios.get(`${httpPath}` + url, {
            params: params
        }).then(res => {
            resolve(res)
        }).catch(err => {
            reject(err.data)
        })
    })
}
